<template>
  <!-- <div class="wd-card-body" style="padding: 0;"> -->
  <div ref="echarts" class="h-100 w-100"></div>
  <!-- </div> -->
</template>
<script>
import Echarts from "echarts";
export default {
  name: "commonCharts",
  title: "图标统计",
  props: {
    titleCharts: "",
    renderColor: {
      type: Array,
      default: function() {
        return ["#1F9CFF", "#56CD73"];
      }
    }
  },
  data() {
    return {
      chart: null
    };
  },
  methods: {
    setData(dataSource, themedata) {
      this.setOption(dataSource, themedata, this.titleCharts);
    },
    setOption(data, dataTheme, title) {
      let _this = this;
      this.chart.setOption({
        color: _this.renderColor,
        title: {
          text: title,
          left: "center"
        },
        tooltip: {
          trigger: "item",
          formatter: "{b} : {c} ({d}%)"
        },
        legend: {
          orient: "vertical",
          left: "60%",
          top: "center",
          data: dataTheme
        },
        series: [
          {
            type: "pie",
            radius: "65%",
            center: ["30%", "50%"],
            selectedMode: "single",
            data: data,
            label: {
              normal: {
                position: "inner",
                formatter: item => {
                  if (item.data.value) {
                    return item.data.value;
                  } else {
                    return "";
                  }
                }
              }
            },
            itemStyle: {
              emphasis: {
                shadowBlur: 10,
                shadowOffsetX: 0,
                shadowColor: "rgba(0, 0, 0, 0.5)"
              }
            }
          }
        ]
      });
    },
    init() {
      let dom = this.$refs.echarts;
      this.chart = Echarts.init(dom);
      window.addEventListener("resize", this.chart.resize);
    }
  },
  mounted() {
    this.init();
  }
};
</script>
<style lang='scss'>
</style>
